<?php
class ml_model_dbWapContent extends Lib_datamodel_db
{
    public function __construct() {
        
        $db_config = ml_factory::load_standard_conf ( 'db' );
        
        parent::__construct ( 'wap_content', $db_config ['wap_content'] );
    }
    public function insert_content($data){
        $uid = $data['uid'];
        if(!$this->init_db($uid , self::DB_MASTER  ))
            return false;
        $array['rid'] = $data['rid'];
        $array['uid'] = $data['uid'];
        $array['wb_pid'] = $data['wb_pid'];
        $array['wb_pic_id'] = $data['wb_pic_id'];
        $array['type'] = $data['type'];
        $array['content'] = $data['content'];
        $array['pic_id'] = $data['pic_id'];
        $array['from'] = empty($data['from']) ? ML_FROM_PHONE : $data['from'];
        $array['userfeed_rid'] = $data['userfeed_rid'];
        $array['status'] = 1;
        $array['cip'] = $data['cip'];
        return $this->insert($array);
    }
    
    public function get_by_wb_picid($uid,$wb_pic_id){
        if(!$this->init_db($uid, self::DB_SLAVE   ))
            return false;
                
        $sql = 'select `rid`,`wb_pid`,`uid`,`type`,`content`,`pic_id`,`userfeed_rid`,`from`,`ctime`  from `'.$this->table.'` where `wb_pic_id`=\''.$wb_pic_id.'\' and status!=9 ';
        return $this->fetch_row($sql);
    }
    
    public function get_by_rid($uid,$rid){
        if(!$this->init_db($uid, self::DB_SLAVE  ))
            return false;
                
        $sql = 'select `rid`,`wb_pid`,`uid`,`type`,`content`,`pic_id`,`userfeed_rid`,`from`,`ctime`  from `'.$this->table.'` where `rid`=\''.$rid.'\' and status!=9 ';
        return $this->fetch_row($sql);
    }
    
    public function update_wb_pid($rid,$wb_pid){
        $uid = ml_tool_resid::resid2uid($rid);
        if(!$this->init_db($uid , self::DB_MASTER   ))
            return false;
        $aUpdate = array(
            'wb_pid' => $wb_pid
        );
        return $this->update($aUpdate , '`rid`="'.$this->escape($rid).'"' , 1);
    }
    
    public function get_content_by_time($begin,$num=20){
        if(!$this->init_db('' , self::DB_SLAVE  ))   //目前不分表
            return false;
        $limit=" LIMIT  $begin,$num  ";
        $sql = 'select `rid`,`wb_pid`,`uid`,`type`,`content`,`pic_id`,`userfeed_rid`,`from`,`ctime`  FROM `'.$this->table.'` where  `status` !=9  ORDER BY `ctime` DESC   '.$limit  ;
        return $this->fetch($sql);
    }
    

    
    
    
}
?>